package com.company.math;

/**
 * @author jrue
 * @description https://leetcode-cn.com/problems/power-of-two/
 * @date 2019/11/14 16:56
 * 给定一个整数，编写一个函数来判断它是否是 2 的幂次方。
 */
public class IsPowerOfTwo {

    public static void main(String[] args) {
        System.out.println(isPowerOfTwo(218));
    }

    public static boolean isPowerOfTwo(int n) {

        while (n != 0 && n % 2== 0) {
            n = n /2;
        }

        return n == 1;
    }

}
